#include "Logger.h"
#include "Exceptions.h"
#include <ctime>
#include <cstdarg>
#include <cstdio>
#include <iostream>

namespace BPL
{
LoggerPtr Logger::mpv_instance = LoggerPtr();

Logger::~Logger()
{

}

void Logger::setLogger(LoggerPtr Logger)
{
    destroy();
    mpv_instance = Logger;
}

void Logger::destroy()
{
    mpv_instance = LoggerPtr();
}

void Logger::log(const char* Format, ...)
{
    Assert(mpv_instance != NULL);

    char sBuffer[512];
    va_list Params;
    va_start(Params, Format);
    vsprintf(sBuffer, Format, Params);
    va_end(Params);

    mpv_instance->write(sBuffer);
}

Logger& Logger::log()
{
    return *mpv_instance;
}

std::string Logger::currentDate() const
{
    char sTime[24];
    time_t CurrentTime = time(NULL);
    strftime(sTime, sizeof(sTime), "%d/%m/%Y", localtime(&CurrentTime));

    return sTime;
}

std::string Logger::currentTime() const
{
    char sTime[24];
    time_t CurrentTime = time(NULL);
    strftime(sTime, sizeof(sTime), "%H:%M:%S", localtime(&CurrentTime));

    return sTime;
}

}
